
package std.process
import std.collection.*
import std.fs.*
import std.io.*
import std.sync.*

import std.time.*

@Deprecated[message: "Use related global functions in the std.env instead."]
@!APILevel[
    since: "22"
]
public class CurrentProcess <: Process {
    @!APILevel[
        since: "22"
    ]
    public prop stdErr: OutputStream
    
    @!APILevel[
        since: "22"
    ]
    public prop stdOut: OutputStream
    
    @!APILevel[
        since: "22"
    ]
    public prop stdIn: InputStream
    
    /**
    * @throws IndexOutOfBoundsException
    * @throws IllegalArgumentException
    */
    @!APILevel[
        since: "22",
        throwexception: true
    ]
    public prop arguments: Array<String>
    
    @!APILevel[
        since: "22"
    ]
    public prop homeDirectory: Path
    
    /**
    * @throws IllegalMemoryException
    * @throws IllegalSynchronizationStateException
    * @throws IllegalArgumentException
    */
    @!APILevel[
        since: "22",
        throwexception: true
    ]
    public prop tempDirectory: Path
    
    /**
    * @throws IllegalMemoryException
    * @throws IllegalSynchronizationStateException
    * @throws IllegalArgumentException
    */
    @!APILevel[
        since: "22",
        throwexception: true
    ]
    public func getEnv(key: String): Option<String>
    
    /**
    * @throws IllegalMemoryException
    * @throws IllegalSynchronizationStateException
    * @throws IllegalArgumentException
    */
    @!APILevel[
        since: "22",
        throwexception: true
    ]
    public func setEnv(k: String, v: String): Unit
    
    /**
    * @throws IllegalMemoryException
    * @throws IllegalSynchronizationStateException
    * @throws IllegalArgumentException
    */
    @!APILevel[
        since: "22",
        throwexception: true
    ]
    public func removeEnv(k: String): Unit
    
    @!APILevel[
        since: "22"
    ]
    public func atExit(callback: () -> Unit): Unit
    
    /**
    * @throws OutOfMemoryError
    * @throws IllegalArgumentException
    * @throws IndexOutOfBoundsException
    * @throws ProcessException
    */
    @!APILevel[
        since: "22",
        throwexception: true
    ]
    public func exit(code: Int64): Nothing
}

@!APILevel[
    since: "22"
]
public open class Process {
    /**
    * @throws OutOfMemoryError
    * @throws IllegalArgumentException
    * @throws IndexOutOfBoundsException
    * @throws ProcessException
    */
    @Deprecated[message: "CurrentProcess has been marked as deprecated, use related global functions in the std.env instead."]
    @!APILevel[
        since: "22",
        throwexception: true
    ]
    public static prop current: CurrentProcess
    
    @!APILevel[
        since: "22"
    ]
    public prop pid: Int64
    
    /**
    * @throws ProcessException
    */
    @!APILevel[
        since: "22",
        throwexception: true
    ]
    public prop name: String
    
    /**
    * @throws ProcessException
    */
    @!APILevel[
        since: "22",
        throwexception: true
    ]
    public prop command: String
    
    /**
    * @throws IndexOutOfBoundsException
    * @throws ArithmeticException
    * @throws IllegalArgumentException
    */
    @!APILevel[
        since: "22",
        throwexception: true
    ]
    public prop startTime: DateTime
    
    @!APILevel[
        since: "22"
    ]
    public prop systemTime: Duration
    
    @!APILevel[
        since: "22"
    ]
    public prop userTime: Duration
    
    /**
    * @throws ProcessException
    */
    @Deprecated
    @!APILevel[
        since: "22",
        throwexception: true
    ]
    public open prop arguments: Array<String>
    
    /**
    * @throws ProcessException
    */
    @Deprecated[message: "Use global function `public func getCommandLine(): Array<String>` in std.env instead."]
    @!APILevel[
        since: "22",
        throwexception: true
    ]
    public prop commandLine: Array<String>
    
    /**
    * @throws ProcessException
    */
    @Deprecated[message: "Use global function `public func getHomeDirectory(): Path` in std.env instead."]
    @!APILevel[
        since: "22",
        throwexception: true
    ]
    public prop workingDirectory: Path
    
    /**
    * @throws IllegalArgumentException
    * @throws IndexOutOfBoundsException
    * @throws ProcessException
    */
    @Deprecated[message: "Use global function `public func getVariables(): Array<(String, String)>` in std.env instead."]
    @!APILevel[
        since: "22",
        throwexception: true
    ]
    public prop environment: Map<String, String>
    
    /**
    * @throws OutOfMemoryError
    * @throws IndexOutOfBoundsException
    * @throws ProcessException
    * @throws IllegalArgumentException
    */
    @Deprecated[message: "Use global function `public func findProcess(pid: Int64): Process` instead."]
    @!APILevel[
        since: "22",
        throwexception: true
    ]
    public static func of(pid: Int64): Process
    
    /**
    * @throws OutOfMemoryError
    * @throws IndexOutOfBoundsException
    * @throws IllegalMemoryException
    * @throws FSException
    * @throws ProcessException
    * @throws IllegalArgumentException
    */
    @Deprecated[message: "Use global function `public func launch(command: String, arguments: Array<String>, workingDirectory!: ?Path = None, environment!: ?Map<String, String> = None, stdIn!: ProcessRedirect = Inherit, stdOut!: ProcessRedirect = Inherit, stdErr!: ProcessRedirect = Inherit): SubProcess` instead."]
    @!APILevel[
        since: "22",
        throwexception: true
    ]
    public static func start(command: String, arguments: Array<String>, workingDirectory!: ?Path = None,
        environment!: ?Map<String, String> = None, stdIn!: ProcessRedirect = Inherit,
        stdOut!: ProcessRedirect = Inherit, stdErr!: ProcessRedirect = Inherit): SubProcess
    
    /**
    * @throws IndexOutOfBoundsException
    * @throws IllegalMemoryException
    * @throws IllegalArgumentException
    * @throws OutOfMemoryError
    * @throws TimeoutException
    * @throws FSException
    * @throws ArithmeticException
    * @throws ProcessException
    */
    @Deprecated[message: "Use global function `public func execute(command: String, arguments: Array<String>, workingDirectory!: ?Path = None, environment!: ?Map<String, String> = None, stdIn!: ProcessRedirect = Inherit, stdOut!: ProcessRedirect = Inherit, stdErr!: ProcessRedirect = Inherit, timeout!: ?Duration = None): Int64` instead."]
    @!APILevel[
        since: "22",
        throwexception: true
    ]
    public static func run(command: String, arguments: Array<String>,
            workingDirectory!: ?Path = None,
            environment!: ?Map<String, String> = None,
            stdIn!: ProcessRedirect = Inherit,
            stdOut!: ProcessRedirect = Inherit,
            stdErr!: ProcessRedirect = Inherit,
            timeout!: ?Duration = None): Int64
    
    /**
    * @throws IllegalMemoryException
    * @throws OverflowException
    * @throws IndexOutOfBoundsException
    * @throws IllegalArgumentException
    * @throws OutOfMemoryError
    * @throws TimeoutException
    * @throws FSException
    * @throws ArithmeticException
    * @throws ProcessException
    */
    @Deprecated[message: "Use global function `public func executeWithOutput(command: String, arguments: Array<String>, workingDirectory!: ?Path = None, environment!: ?Map<String, String> = None, stdIn!: ProcessRedirect = Inherit, stdOut!: ProcessRedirect = Pipe, stdErr!: ProcessRedirect = Pipe): (Int64, Array<Byte>, Array<Byte>)` instead."]
    @!APILevel[
        since: "22",
        throwexception: true
    ]
    public static func runOutput(command: String, arguments: Array<String>, workingDirectory!: ?Path = None,
        environment!: ?Map<String, String> = None, stdIn!: ProcessRedirect = Inherit, stdOut!: ProcessRedirect = Pipe,
        stdErr!: ProcessRedirect = Pipe): (Int64, Array<Byte>, Array<Byte>)
    
    @!APILevel[
        since: "22"
    ]
    public func isAlive(): Bool
    
    /**
    * @throws ProcessException
    * @throws IllegalArgumentException
    */
    @!APILevel[
        since: "22",
        throwexception: true
    ]
    public func terminate(force!: Bool = false): Unit
}

@!APILevel[
    since: "22"
]
public enum ProcessRedirect {
    @!APILevel[
        since: "22"
    ]
    Inherit |
    @!APILevel[
        since: "22"
    ]
    Pipe |
    @!APILevel[
        since: "22"
    ]
    FromFile(File) |
    @!APILevel[
        since: "22"
    ]
    Discard
}

/**
* @throws OutOfMemoryError
* @throws IndexOutOfBoundsException
* @throws ProcessException
* @throws IllegalArgumentException
*/
@!APILevel[
    since: "22",
    throwexception: true
]
public func findProcess(pid: Int64): Process

/**
* @throws OutOfMemoryError
* @throws IndexOutOfBoundsException
* @throws IllegalMemoryException
* @throws FSException
* @throws ProcessException
* @throws IllegalArgumentException
*/
@!APILevel[
    since: "22",
    throwexception: true
]
public func launch(command: String, arguments: Array<String>, workingDirectory!: ?Path = None,
    environment!: ?Map<String, String> = None, stdIn!: ProcessRedirect = Inherit, stdOut!: ProcessRedirect = Inherit,
    stdErr!: ProcessRedirect = Inherit): SubProcess

/**
* @throws IndexOutOfBoundsException
* @throws IllegalMemoryException
* @throws IllegalArgumentException
* @throws OutOfMemoryError
* @throws TimeoutException
* @throws FSException
* @throws ArithmeticException
* @throws ProcessException
*/
@!APILevel[
    since: "22",
    throwexception: true
]
public func execute(command: String, arguments: Array<String>, workingDirectory!: ?Path = None,
    environment!: ?Map<String, String> = None, stdIn!: ProcessRedirect = Inherit, stdOut!: ProcessRedirect = Inherit,
    stdErr!: ProcessRedirect = Inherit, timeout!: ?Duration = None): Int64

/**
* @throws IllegalMemoryException
* @throws OverflowException
* @throws IndexOutOfBoundsException
* @throws IllegalArgumentException
* @throws OutOfMemoryError
* @throws TimeoutException
* @throws FSException
* @throws ArithmeticException
* @throws ProcessException
*/
@!APILevel[
    since: "22",
    throwexception: true
]
public func executeWithOutput(command: String, arguments: Array<String>, workingDirectory!: ?Path = None,
    environment!: ?Map<String, String> = None, stdIn!: ProcessRedirect = Inherit, stdOut!: ProcessRedirect = Pipe,
    stdErr!: ProcessRedirect = Pipe): (Int64, Array<Byte>, Array<Byte>)

@!APILevel[
    since: "22"
]
public class ProcessException <: IOException {
    @!APILevel[
        since: "22"
    ]
    public init(message: String)
}

@!APILevel[
    since: "22"
]
public class SubProcess <: Process {
    @!APILevel[
        since: "22"
    ]
    public prop stdInPipe: OutputStream
    
    @!APILevel[
        since: "22"
    ]
    public prop stdOutPipe: InputStream
    
    @!APILevel[
        since: "22"
    ]
    public prop stdErrPipe: InputStream
    
    @Deprecated[message: "Use `public prop stdErrPipe: InputStream` instead."]
    @!APILevel[
        since: "22"
    ]
    public prop stdErr: InputStream
    
    @Deprecated[message: "Use `public prop stdOutPipe: InputStream` instead."]
    @!APILevel[
        since: "22"
    ]
    public prop stdOut: InputStream
    
    @Deprecated[message: "Use `public prop stdInPipe: OutputStream` instead."]
    @!APILevel[
        since: "22"
    ]
    public prop stdIn: OutputStream
    
    /**
    * @throws TimeoutException
    * @throws ArithmeticException
    * @throws ProcessException
    */
    @!APILevel[
        since: "22",
        throwexception: true
    ]
    public func wait(timeout!: ?Duration = None): Int64
    
    /**
    * @throws OverflowException
    * @throws IndexOutOfBoundsException
    * @throws IllegalArgumentException
    * @throws TimeoutException
    * @throws ArithmeticException
    * @throws ProcessException
    */
    @!APILevel[
        since: "22",
        throwexception: true
    ]
    public func waitOutput(): (Int64, Array<Byte>, Array<Byte>)
}

